/*
 * @Author: Sam
 * @Date: 2020-10-12 15:23:33
 * @LastEditTime: 2021-04-22 11:20:28
 * @LastEditors: Sam
 * @Description: 
 * @FilePath: \resourcesf:\thework\tofba-client\src\utils\validate.js
 * 可以输入预定的版权声明、个性签名、空行等
 */

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal (path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

export function pickerOptions () {

  return {
    shortcuts: [{
      text: '今天',
      onClick (picker) {
        picker.$emit('pick', new Date());
      }
    }, {
      text: '昨天',
      onClick (picker) {
        const date = new Date();
        date.setTime(date.getTime() - 3600 * 1000 * 24);
        picker.$emit('pick', date);
      }
    }, {
      text: '一周前',
      onClick (picker) {
        const date = new Date();
        date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
        picker.$emit('pick', date);
      }
    }]
  }
}

export function future () {

  return {
    shortcuts: [{
      text: '今天',
      onClick (picker) {
        picker.$emit('pick', new Date());
      }
    }, {
      text: '明天',
      onClick (picker) {
        const date = new Date();
        date.setTime(date.getTime() + 3600 * 1000 * 24);
        picker.$emit('pick', date);
      }
    }, {
      text: '一周后',
      onClick (picker) {
        const date = new Date();
        date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
        picker.$emit('pick', date);
      }
    }]
  }
}
export function timeLimit () {

  return {
    shortcuts: [{
      text: '最近一周',
      onClick (picker) {
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
        picker.$emit('pick', [start, end]);
      }
    }, {
      text: '最近一个月',
      onClick (picker) {
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
        picker.$emit('pick', [start, end]);
      }
    }, {
      text: '最近三个月',
      onClick (picker) {
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
        picker.$emit('pick', [start, end]);
      }
    }]
  }
}